#include "RoomSuite.h"
#include "Reservation.h"


RoomSuite::RoomSuite(int roomNumber) : Room( roomNumber ) {
	roomType = Room::SUITE;
	bedCount = 2;
}

RoomSuite::RoomSuite( ifstream & inn, int roomNumber) : Room( inn, roomNumber ) {
	roomType = Room::SUITE;
	
	inn >> additionalBeds;		inn.ignore();
	inn >> area;				inn.ignore();
	getline( inn, description, '\n' );
}

void RoomSuite::WriteToFile(ofstream &file) {
	Room::WriteToFile(file);
	
	file << additionalBeds;
	file << endl;
	
	file << area;
	file << endl;
	
	file << description;
	file << endl;
}

void RoomSuite::display() {
	Room::display();
	
	/* Print the description without line breaks by printing
	 * no more than 40 characters at a time.
	 * This function works if no words are longer than 40 characters.
	 */
	printf("\tDescription:\n");
	
	int printed = 0;
	while (printed < description.length()) {
		int remaining = (int)description.length() - printed;
		int sublen = min(remaining, 40);
		
		/* Only split the strings at spaces */
		if (sublen == 40) {
			char *c = &description[printed+sublen];
			while ((*c != ' ' && *c != '\n') && sublen >= 0) {
				sublen--;
				c--;
			}
			
			/* Error handling - "sublen <= 0" */
			if (sublen <= 0) {
				printf("\t\t<DESCRIPTION ERROR>\n");
				return;
			}
		}
		
		/* Cut and print the substring */
		string sub = description.substr(printed, sublen);
		
		printf("\t\t%s\n", sub.c_str());
		printed += sublen+1;
	}
}

int RoomSuite::getBedCount() {
	return bedCount + additionalBeds;
}























